<template>
  <div class="big">
    <div class="back" v-if="result">
      <div class="black"></div>
      <div class="img"><img :src="result.data.artist.cover" /></div>
    </div>
    <div class="brief" v-if="result">
      <div class="name">{{ result.data.artist.name }}</div>
      <h2>歌手简介</h2>
      <br />
      <div class="desc">{{ result.data.artist.briefDesc }}</div>
    </div>
    <div class="hot" v-if="res">
      <h1>热门单曲</h1>
      <loading v-if="res.songs.length == 0"></loading>
      <music-list
        v-else
        @play="$emit('play', $event)"
        :songlist="songList"
        :shownum="true"
      ></music-list>
    </div>
  </div>
</template>
<script>
import MusicList from "@/components/MusicList";
import Loading from "@/components/Loading";
export default {
  name: "Singer",
  props: {
    id: [String, Number],
  },
  data() {
    return {
      songList: [],
      result: null,
      res: null,
    };
  },
  components: {
    MusicList,
    Loading,
  },
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      vm.axios
        .get(`/artist/detail?id=${vm.id}`)
        .then((result) => {
          vm.result = result;
        })
    });
    next((vm) => {
      vm.axios.get(`/artist/top/song?id=${vm.id}`).then((res) => {
        vm.res = res;
        let songList = res.songs.map((v) => {
          v.song = {
            privilege: v.privilege,
            artists: v.ar,
            album: v.al,
          };
          return v;
        });
        vm.songList = songList;
      });
    });
  },
};
</script>

<style lang="less" scoped>
.big {
  padding-bottom: 50px;
}
.back {
  position: relative;
  top: 0;
  .black {
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    position: absolute;
  }
  .img {
    width: 100%;
    img {
      width: 100%;
      z-index: -1;
    }
  }
  .singer {
    width: 100px;
    margin: -55px auto;
    z-index: 4;
    padding-top: 60px;
  }
}
.brief {
  margin: 10px 2px;
  border-bottom: 2px var(--cy-Color) solid;
  padding: 10px 2px;
  line-height: 18px;
  position: relative;
  h2 {
    font-weight: bold;
    color: rgb(66, 66, 66);
    font-size: 20px;
    line-height: 20px;
  }
  .name {
    position: absolute;
    top: -40px;
    font-size: 25px;
    color: #fff;
    z-index: 4;
  }
  .desc {
    font-size: 14px;
    color: rgb(94, 94, 94);
  }
}
.hot {
  h1 {
    padding-bottom: 10px;
    font-size: 25px;
    font-weight: bold;
    color: rgb(66, 66, 66);
    border-bottom: 2px solid var(--cy-Color);
  }
}
</style>